<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>管理中心 - 云学堂</title>
    <link rel="stylesheet" th:href="@{/css/common.css}">
    <link rel="stylesheet" th:href="@{/css/index.css}">
    <link rel="stylesheet" th:href="@{/css/navbar.css}">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <script th:src="@{/js/jquery.min.js}"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg">
        <div class="container">
            <a class="navbar-brand" href="#">云学堂</a>
            <div class="collapse navbar-collapse">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/resource/list}">学习资源</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/assignment/list}">作业与考试</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/forum/list}">交流互动</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" th:href="@{/admin/index}">管理中心</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/user/digital}">个人中心</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/logout}">退出</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="page-container">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="page-title"><i class="fas fa-tachometer-alt me-2"></i>管理面板</h2>
            <div>
                <span class="me-3"><i class="fas fa-user-circle"></i> <span
                        th:text="${session.loginUser.username}">用户名</span></span>
            </div>
        </div>

        <!-- 统计卡片 -->
        <div class="row mb-4">
            <div class="col-md-3 mb-3">
                <div class="card text-center">
                    <div class="card-body">
                        <h5 class="card-title">用户总数</h5>
                        <p class="display-4" th:text="${users.size()}"></p>
                        <i class="fas fa-users fa-2x text-primary"></i>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-3">
                <div class="card text-center">
                    <div class="card-body">
                        <h5 class="card-title">管理员数</h5>
                        <p class="display-4" th:text="${admins.size()}"></p>
                        <i class="fas fa-user-shield fa-2x text-success"></i>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-3">
                <div class="card text-center">
                    <div class="card-body">
                        <h5 class="card-title">学习资源</h5>
                        <p class="display-4" th:text="${resources.size()}"></p>
                        <i class="fas fa-book fa-2x text-info"></i>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-3">
                <div class="card text-center">
                    <div class="card-body">
                        <h5 class="card-title">作业与考试</h5>
                        <p class="display-4" th:text="${assignments.size()}"></p>
                        <i class="fas fa-tasks fa-2x text-warning"></i>
                    </div>
                </div>
            </div>
        </div>

        <!-- 标签页导航 -->
        <ul class="nav nav-tabs mb-4" id="adminTabs" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile"
                        type="button" role="tab">个人中心
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="users-tab" data-bs-toggle="tab" data-bs-target="#users" type="button"
                        role="tab">用户管理
                </button>
            </li>
            <li th:if="${session.loginUser.role=='superAdmin'}" class="nav-item" role="presentation">
                <button class="nav-link" id="admins-tab" data-bs-toggle="tab" data-bs-target="#admins" type="button"
                        role="tab">管理员管理
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="resources-tab" data-bs-toggle="tab" data-bs-target="#resources"
                        type="button" role="tab">学习资源管理
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="assignments-tab" data-bs-toggle="tab" data-bs-target="#assignments"
                        type="button" role="tab">作业与考试管理
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="forum-tab" data-bs-toggle="tab" data-bs-target="#forum" type="button"
                        role="tab">交流互动管理
                </button>
            </li>
        </ul>

        <!-- 标签页内容 -->
        <div class="tab-content" id="adminTabsContent">
            <!-- 个人中心 -->
            <div class="tab-pane fade show active" id="profile" role="tabpanel">
                <div class="row">
                    <div class="col-md-4">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0"><i class="fas fa-user me-2"></i>个人信息</h5>
                            </div>
                            <div class="card-body text-center">
                                <span th:if="${session.loginUser.avatar != null}"><img
                                        th:src="${session.loginUser.avatar}" alt="头像"
                                        class="rounded-circle mb-3 user-avatar"
                                        width="150" height="150"></span>
                                <span th:if="${session.loginUser.avatar == null}"><img src="/img/defaultAvatar.png"
                                                                                       alt="头像"
                                                                                       class="rounded-circle mb-3 user-avatar"
                                                                                       width="150" height="150"></span>
                                <h5 th:text="${session.loginUser.username}">用户名</h5>
                                <p class="text-muted" th:text="${session.loginUser.role}">角色</p>
                                <button class="btn btn-primary" data-bs-toggle="modal"
                                        data-bs-target="#updateAvatarModal"><i class="fas fa-camera me-1"></i>更换头像
                                </button>
                            </div>

                        </div>
                    </div>
                    <div class="col-md-8">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0"><i class="fas fa-lock me-2"></i>修改密码</h5>
                            </div>
                            <div class="card-body">
                                <form>
                                    <div class="mb-3">
                                        <label for="oldPassword" class="form-label">原密码</label>
                                        <input type="password" class="form-control" id="oldPassword" required>
                                    </div>
                                    <div class="mb-3">
                                        <label for="newPassword" class="form-label">新密码</label>
                                        <input type="password" class="form-control" id="newPassword" required>
                                    </div>
                                    <div class="mb-3">
                                        <label for="confirmPassword" class="form-label">确认新密码</label>
                                        <input type="password" class="form-control" id="confirmPassword" required>
                                    </div>
                                    <button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>修改密码
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 用户管理 -->
            <div class="tab-pane fade" id="users" role="tabpanel">
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="mb-0"><i class="fas fa-users me-2"></i>用户管理</h4>
                    <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addUserModal"><i
                            class="fas fa-plus me-1"></i>添加用户
                    </button>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>角色</th>
                            <th>注册时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="user : ${users}">
                            <td th:text="${user.id}"></td>
                            <td th:text="${user.username}"></td>
                            <td th:if="${user.role=='ordinaryUser'}"><span class="badge bg-secondary"
                                                                           th:text="普通用户"></span></td>
                            <td th:if="${user.role=='ordinaryAdmin'}"><span class="badge bg-warning"
                                                                            th:text="管理员"></span></td>
                            <td th:if="${user.role=='superAdmin'}"><span class="badge bg-success"
                                                                         th:text="超级管理员"></span></td>
                            <td th:text="${#temporals.format(user.createTime,'yyyy-MM-dd HH:mm')}"></td>
                            <td th:if="${user.status==1}"><span class="status-badge success" th:text="正常"></span>
                            <td th:if="${user.status==0}"><span class="status-badge danger" th:text="已锁定"></span>
                            </td>
                            <td th:if="${user.role!='superAdmin'}">
                                <button class="btn btn-sm btn-danger"
                                        th:attr="onclick='delUser('+ ${user.id}+', this)'"><i class="fas fa-trash"></i>
                                    删除
                                </button>
                                <button class="btn btn-sm btn-info me-1"
                                        th:attr="onclick='editUser('+ ${user.id}+', this)'"><i class="fas fa-edit"></i>
                                    编辑
                                </button>
                                <button id="adminBtn" class="btn btn-sm btn-success me-1"
                                        th:if="${user.role=='ordinaryUser'}"
                                        th:attr="onclick='addAdmin('+ ${user.id}+', this)'"
                                        th:text="'设为管理员'"><i class="fas fa-user-shield"></i> 设为管理员
                                </button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 管理员管理 -->
            <div th:if="${session.loginUser.role=='superAdmin'}" class="tab-pane fade" id="admins" role="tabpanel">
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="mb-0"><i class="fas fa-user-shield me-2"></i>管理员管理</h4>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>角色</th>
                            <th>注册时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="admin : ${admins}">
                            <td th:text="${admin.id}"></td>
                            <td th:text="${admin.username}"></td>
                            <td><span class="badge bg-info"
                                      th:text="${admin.role=='superAdmin'?'超级管理员':'普通管理员'}"></span></td>
                            <td th:text="${#temporals.format(admin.createTime,'yyyy-MM-dd HH:mm')}"></td>
                            <td><span class="status-badge success" th:text="${admin.status==1?'正常':'已锁定'}"></span>
                            </td>
                            <td>
                                <button class="btn btn-sm btn-info me-1"
                                        th:attr="onclick='editUser('+ ${admin.id}+', this)'">
                                    <i class="fas fa-edit"></i> 编辑
                                </button>
                                <button class="btn btn-sm btn-warning me-1"
                                        th:attr="onclick='demoteAdmin('+ ${admin.id}+', this)'"><i
                                        class="fas fa-user"></i> 降为用户
                                </button>
                                <button class="btn btn-sm btn-danger"
                                        th:attr="onclick='delAdmin('+ ${admin.id}+', this)'"><i
                                        class="fas fa-trash"></i> 删除
                                </button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 学习资源管理 -->
            <div class="tab-pane fade" id="resources" role="tabpanel">
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="mb-0"><i class="fas fa-book me-2"></i>学习资源管理</h4>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>类型</th>
                            <th>专业</th>
                            <th>上传时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="resource:${resources}">
                            <td th:text="${resource.id}"></td>
                            <td th:text="${resource.title}"></td>
                            <td th:text="${resource.type}"></td>
                            <td th:text="${majorMap.get(resource.majorId)?: '未分类'}"></td>
                            <td th:text="${#temporals.format(resource.createdTime,'yyyy-MM-dd HH:mm')}"></td>
                            <td>
                                <button class="btn btn-sm btn-info me-1"
                                        th:attr="onclick='viewResource('+${resource.id}+',this)'">
                                    <i class="fas fa-eye"></i> 查看
                                </button>
                                <button
                                        th:attr="onclick='delResource('+${resource.id}+',this)'"
                                        class="btn btn-sm btn-danger"><i class="fas fa-trash"></i> 删除
                                </button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 作业与考试管理 -->
            <div class="tab-pane fade" id="assignments" role="tabpanel">
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="mb-0"><i class="fas fa-tasks me-2"></i>作业与考试管理</h4>
                    <button class="btn btn-primary"  data-bs-toggle="modal" data-bs-target="#addAssignmentModal"><i class="fas fa-plus me-1"></i>发布作业/考试</button>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>专业</th>
                            <th>发布时间</th>
                            <th>截止时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="assignment : ${assignments}">
                            <td th:text="${assignment.id}"></td>
                            <td th:text="${assignment.title}">Java基础练习题</td>
                            <td th:text="${majorMap.get(assignment.majorId)?: '未分类'}"></td>
                            <td th:text="${#temporals.format(assignment.createdTime,'yyyy-MM-dd HH:mm')}"></td>
                            <td th:text="${#temporals.format(assignment.deadline,'yyyy-MM-dd HH:mm')}"></td>
                            <td>
                                <button class="btn btn-sm btn-info me-1"
                                        th:attr="onclick='viewAssignment('+${assignment.id}+',this)'">
                                    <i class="fas fa-eye"></i> 查看
                                </button>
                                <button
                                        th:attr="onclick='delAssignment('+${assignment.id}+',this)'"
                                        class="btn btn-sm btn-danger"><i class="fas fa-trash"></i> 删除
                                </button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 交流互动管理 -->
            <div class="tab-pane fade" id="forum" role="tabpanel">
                <ul class="nav nav-tabs mb-3">
                    <li class="nav-item">
                        <button class="nav-link active" data-bs-toggle="tab" data-bs-target="#posts">帖子管理</button>
                    </li>
                    <li class="nav-item">
                        <button class="nav-link" data-bs-toggle="tab" data-bs-target="#replies">评论管理</button>
                    </li>
                </ul>

                <div class="tab-content">
                    <div class="tab-pane fade show active" id="posts">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <h4 class="mb-0"><i class="fas fa-list me-2"></i>帖子管理</h4>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>标题</th>
                                    <th>作者</th>
                                    <th>发布时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="post : ${forums}">
                                    <td th:text="${post.id}"></td>
                                    <td th:text="${post.title}"></td>
                                    <td th:text="${userMap.get(post.authorId)?: '未知用户'}"></td>
                                    <td th:text="${#temporals.format(post.createdTime,'yyyy-MM-dd HH:mm')}"></td>
                                    <td>
                                        <span class="status-badge"
                                              th:classappend="${post.isTop == 1 ? 'warning' : 'secondary'}"
                                              th:text="${post.isTop == 1 ? '已置顶' : '未置顶'}"></span>
                                        <span class="status-badge"
                                              th:classappend="${post.isElite == 1 ? 'success' : 'secondary'}"
                                              th:text="${post.isElite == 1 ? '精华' : '普通'}"></span>
                                    </td>

                                    <td>
                                        <button class="btn btn-sm me-1"
                                                th:classappend="${post.isTop == 1 ? 'btn-warning' : 'btn-info'}"
                                                th:attr="onclick='topPost('+${post.id}+','+${post.isTop}+',this)'">
                                            <i class="fas fa-thumbtack"></i>
                                            <span th:text="${post.isTop == 1 ? '取消置顶' : '置顶'}"></span>
                                        </button>
                                        <button class="btn btn-sm me-1"
                                                th:classappend="${post.isElite == 1 ? 'btn-warning' : 'btn-success'}"
                                                th:attr="onclick='enhancePost('+${post.id}+','+${post.isElite}+',this)'">
                                            <i class="fas fa-star"></i>
                                            <span th:text="${post.isElite == 1 ? '取消加精' : '加精'}"></span>
                                        </button>
                                        <button th:attr="onclick='delPost('+${post.id}+',this)'"
                                                class="btn btn-sm btn-danger"><i class="fas fa-trash"></i> 删除
                                        </button>
                                    </td>

                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="tab-pane fade" id="replies">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <h4 class="mb-0"><i class="fas fa-comments me-2"></i>评论管理</h4>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>内容</th>
                                    <th>作者</th>
                                    <th>所属帖子</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="reply : ${replies}">
                                    <td th:text="${reply.id}"></td>
                                    <td th:text="${reply.content}"></td>
                                    <td th:text="${userMap.get(reply.authorId)?: '未知用户'}"></td>
                                    <td th:text="${postMap.get(reply.postId)?: '未知帖子'}"></td>
                                    <td th:text="${#temporals.format(reply.createdTime,'yyyy-MM-dd HH:mm')}"></td>
                                    <td>
                                        <button th:attr="onclick='delReply('+${reply.id}+',this)'"
                                                class="btn btn-sm btn-danger"><i class="fas fa-trash"></i> 删除
                                        </button>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 添加用户模态框 -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-user-plus me-2"></i>添加用户</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form>
                    <div class="mb-3">
                        <label for="username" class="form-label">用户名</label>
                        <input type="text" class="form-control" id="username" required>
                    </div>
                    <div class="mb-3">
                        <label for="password" class="form-label">密码</label>
                        <input type="password" class="form-control" id="password" required>
                    </div>
                    <div class="mb-3">
                        <label for="role" class="form-label">角色</label>
                        <select class="form-select" id="role">
                            <option value="USER">普通用户</option>
                            <option value="ADMIN">管理员</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i
                        class="fas fa-times me-1"></i>取消
                </button>
                <button type="button" class="btn btn-primary"><i class="fas fa-save me-1"></i>添加</button>
            </div>
        </div>
    </div>
</div>
<!-- 通用编辑模态框 -->
<div class="modal fade" id="editUserModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-user-edit me-2"></i>编辑用户</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="editUserForm">
                    <input type="hidden" id="editUserId">
                    <div class="mb-3">
                        <label for="editPassword" class="form-label">密码</label>
                        <input type="text" class="form-control" id="editPassword" required>
                    </div>
                    <div class="mb-3">
                        <label for="editStatus" class="form-label">状态</label>
                        <select class="form-select" id="editStatus">
                            <option value="1">正常</option>
                            <option value="0">锁定</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i
                        class="fas fa-times me-1"></i>取消
                </button>
                <button type="button" class="btn btn-primary" id="saveUserBtn"><i class="fas fa-save me-1"></i>保存
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 修改头像模态框 -->
<div class="modal fade" id="updateAvatarModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-camera me-2"></i>更换头像</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="avatarForm">
                    <div class="mb-3">
                        <label for="avatar" class="form-label">选择新头像</label>
                        <div class="file-upload-container" onclick="document.getElementById('avatar').click()">
                            <input type="file" class="form-control" id="avatar" name="avatar" accept="image/*" required
                                   style="display: none;">
                            <div class="upload-text">
                                <i class="fas fa-cloud-upload-alt fa-2x"></i>
                                <div>点击上传头像</div>
                            </div>
                        </div>
                        <div class="form-text">支持 JPG、PNG、GIF 格式，文件大小不超过 2MB</div>
                    </div>
                    <div class="text-center" id="avatarPreviewContainer" style="display: none;">
                        <img id="avatarPreview" src="" alt="头像预览" class="rounded-circle mb-3" width="150"
                             height="150">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i
                        class="fas fa-times me-1"></i>取消
                </button>
                <button type="button" class="btn btn-primary" id="uploadAvatarBtn"><i class="fas fa-upload me-1"></i>上传
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 学习资源查看模态框 -->
<div class="modal fade" id="viewResourceModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-book me-2"></i>学习资源详情</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="viewResourceForm">
                    <input type="hidden" id="resourceId">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="mb-3">
                                <label class="form-label"><strong>资源标题</strong></label>
                                <p id="resourceTitle" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>所属专业</strong></label>
                                <p id="resourceMajor" class="form-control-plaintext"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>课程类型</strong></label>
                                <p id="resourceType" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>资源类型</strong></label>
                                <p id="resourceFileType" class="form-control-plaintext"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>文件大小</strong></label>
                                <p id="resourceFileSize" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>上传时间</strong></label>
                                <p id="resourceCreatedTime" class="form-control-plaintext"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>状态</strong></label>
                                <p id="resourceStatus" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>下载次数</strong></label>
                                <p id="resourceDownloadCount" class="form-control-plaintext"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>浏览次数</strong></label>
                                <p id="resourceViewCount" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label"><strong>资源描述</strong></label>
                        <p id="resourceDescription" class="form-control-plaintext"></p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a id="downloadResourceBtn"  class="btn btn-success" target="_blank"><i class="fas fa-download me-1"></i>下载资源</a>
                <button type="button" id="toggleResourceStatusBtn" class="btn btn-warning">
                    <a id="isAvailable" style="display: none"></a><i
                        class="fas fa-ban me-1"></i>禁用资源
                </button>
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i
                        class="fas fa-times me-1"></i>关闭
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 作业查看模态框 -->
<div class="modal fade" id="viewAssignmentModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-tasks me-2"></i>作业详情</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="viewAssignmentForm">
                    <input type="hidden" id="assignmentId">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="mb-3">
                                <label class="form-label"><strong>作业标题</strong></label>
                                <p id="assignmentTitle" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>所属专业</strong></label>
                                <p id="assignmentMajor" class="form-control-plaintext"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>状态</strong></label>
                                <p id="assignmentStatus" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>发布时间</strong></label>
                                <p id="assignmentCreatedTime" class="form-control-plaintext"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label"><strong>截止时间</strong></label>
                                <p id="assignmentDeadline" class="form-control-plaintext"></p>
                            </div>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label"><strong>作业描述</strong></label>
                        <p id="assignmentDescription" class="form-control-plaintext"></p>
                    </div>

                    <div class="mb-3">
                        <label class="form-label"><strong>作业提交列表</strong></label>
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                <tr>
                                    <th>学生</th>
                                    <th>提交时间</th>
                                    <th>状态</th>
                                    <th>得分</th>
                                    <th>评语</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="submissionList">
                                <!-- 提交列表将通过JavaScript动态填充 -->
                                </tbody>
                            </table>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i
                        class="fas fa-times me-1"></i>关闭
                </button>
            </div>
        </div>
    </div>
</div>
<!-- 添加作业模态框 -->
<div class="modal fade" id="addAssignmentModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-tasks me-2"></i>添加作业/考试</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="addAssignmentForm" enctype="multipart/form-data">
                    <div class="mb-3">
                        <label for="assignmentSubTitle" class="form-label">标题</label>
                        <input type="text" class="form-control" id="assignmentSubTitle" name="title" required>
                    </div>

                    <div class="mb-3">
                        <label for="assignmentMajorSelect" class="form-label">专业</label>
                        <select class="form-select" id="assignmentMajorSelect" name="majorId" required>
                            <option value="">请选择专业</option>
                            <option th:each="majorEntry : ${majorMap}" th:value="${majorEntry.key}" th:text="${majorEntry.value}"></option>
                        </select>
                    </div>

                    <div class="mb-3">
                        <label for="assignmentSubDescription" class="form-label">作业/考试描述</label>
                        <textarea class="form-control" id="assignmentSubDescription" name="description" rows="4" required></textarea>
                    </div>

                    <div class="mb-3">
                        <label for="assignmentSubDeadline" class="form-label">截止时间</label>
                        <input type="datetime-local" class="form-control" id="assignmentSubDeadline" name="deadline" required>
                    </div>

                    <div class="mb-3">
                        <label for="assignmentSubFile" class="form-label">附件(可选)</label>
                        <input type="file" class="form-control" id="assignmentSubFile" name="file">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i class="fas fa-times me-1"></i>取消</button>
                <button type="button" class="btn btn-primary" id="saveAssignmentBtn"><i class="fas fa-save me-1"></i>保存</button>
            </div>
        </div>
    </div>
</div>
<!-- 批改作业模态框 -->
<div class="modal fade" id="gradeSubmissionModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><i class="fas fa-edit me-2"></i>批改作业</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="gradeForm" onsubmit="return false;">
                    <input type="hidden" id="submissionId">
                    <div class="mb-3">
                        <label for="score" class="form-label">得分</label>
                        <input type="number" class="form-control" id="score" min="0" step="0.5" required>
                    </div>
                    <div class="mb-3">
                        <label for="comment" class="form-label">评语</label>
                        <textarea class="form-control" id="comment" rows="3"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i class="fas fa-times me-1"></i>取消</button>
                <button type="button" class="btn btn-primary" id="saveGradeBtn"><i class="fas fa-save me-1"></i>保存</button>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/js/index.js}"></script>
</body>
</html>